#ifndef _BRKS_COMMON_DATASERVER_SQLTABLES_H_
#define _BRKS_COMMON_DATASERVER_SQLTABLES_H_

#include "sqlconnection.h"
#include <memory>
#include "glo_def.h"

class MysqlConnection;

class SqlTables
{
public:
	SqlTables(std::shared_ptr<MysqlConnection> sqlConn) : sqlconn_(sqlConn)
	{
	}

	~SqlTables() {}

	bool CreateUserInfo()
	{
		const char* pUserInfoTable = "\
									CREATE TABLE IF NOT EXISTS userinfo(\
									id           int(16)        NOT NULL PRIMARY KEY AUTO_INCREMENT,\
									mobile       varchar(16)    NOT NULL DEFAULT '13000000000',\
									username     varchar(128)   NOT NULL DEFAULT '',\
									verify       int(4)         NOT NULL DEFAULT '0',\
									registertm   timestamp      NOT NULL DEFAULT  CURRENT_TIMESTAMP,\
									money        int(4)         NOT NULL DEFAULT  0,\
									INDEX        mobile_index(mobile)\
									)";

		if (!sqlconn_->Execute(pUserInfoTable))
		{
			LOG_ERROR("create table userinfo table failed. error msg: %s\n", sqlconn_->GetErrInfo());
			return false;
		}
		return true;
	}

	bool CreateBikeTable()
	{
		const char* pBikeInfoTable =  "\
									CREATE TABLE IF NOT EXISTS bikeinfo(\
									id           int            NOT NULL PRIMARY KEY AUTO_INCREMENT,\
									devno        int            NOT NULL,\
									status       tinyint(1)     NOT NULL DEFAULT 0,\
									trouble      int            NOT NULL DEFAULT 0,\
									tmsg         varchar(256)   NOT NULL DEFAULT '',\
									latitude     double(10,6)   NOT NULL DEFAULT 0,\
									longitude    double(10,6)   NOT NULL DEFAULT 0,\
									unique(devno)\
									)";

		if (!sqlconn_->Execute(pBikeInfoTable))
		{
			LOG_ERROR("create table bikeinfo table failed. error msg: %s\n", sqlconn_->GetErrInfo());
			return false;
		}
		return true;
	}

private:
	std::shared_ptr<MysqlConnection> sqlconn_;
};

#endif /* _BRKS_COMMON_DATASERVER_SQLTABLES_H_ */